--[[/**
 * 所受伤害由目标代替我承受
 * [0] n 万分比
-- */]]

---@class BuffEffect228100 : BaseBuffEffect
BuffEffect228100 = ClientFight.CreateClass("BuffEffect228100", ClientFight.BaseBuffEffect)
local t = BuffEffect228100

---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local parameters = {...};
    local attackTarget = buff.skill.target;
    if (attackTarget:isDie()) then
    return IBuffEffect.FAIL;
    end
    if (not parameters[3] ) then
    return IBuffEffect.FAIL;
    end
    local result =parameters[3];
    if (not result:isDamage())then
    return IBuffEffect.FAIL;
    end
    if (not AttackUtils.isDamage(result.state))then
    return IBuffEffect.FAIL;
    end
    local reduce = Utils.calcRatio(result.damage, buff.buffBean.f_BuffEffectValue[1]);
    if (reduce < 1) then
    return IBuffEffect.FAIL;
    end
    local damage = result.damage;
    result.damage = result.damage - reduce;
    if (result.damage < 0) then
    result.setDamage = 0;
    end
    local realDamage = DamageManager.setFighterHp(fight,attackTarget,buff.target,null, DamageResultTypeEnum.NORMAL,-reduce,attackTarget.hp-reduce,true,true,true);
    SkillRoleMgr.savePathFile( "[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff:"
    .. buff.modelId .. " 伤害由目标代替我承受: "..reduce .." 点, 原伤害: " .. damage);
    return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
end

t.New()